/*
 * @lc app=leetcode.cn id=705 lang=javascript
 *
 * [705] 设计哈希集合
 */

// @lc code=start
/**
 * Initialize your data structure here.
 */

const hash = number => number % 2000;

var MyHashSet = function () {
  this.set = []
};

/** 
 * @param {number} key
 * @return {void}
 */
MyHashSet.prototype.add = function (key) {
  const index = hash(key);
  if (!this.set[index]) {
    this.set[index] = [];
  }
  !this.set[index].includes(key) && this.set[index].push(key);
};

/** 
 * @param {number} key
 * @return {void}
 */
MyHashSet.prototype.remove = function (key) {
  const index = hash(key);
  if (!this.set[index]) return;
  const index2 = this.set[index].indexOf(key);
  if (index2 === -1) return;
  this.set[index].splice(index2, 1);
};

/**
 * Returns true if this set contains the specified element 
 * @param {number} key
 * @return {boolean}
 */
MyHashSet.prototype.contains = function (key) {
  const index = hash(key);
  return !!(this.set[index] && this.set[index].includes(key));
};

/**
 * Your MyHashSet object will be instantiated and called as such:
 * var obj = new MyHashSet()
 * obj.add(key)
 * obj.remove(key)
 * var param_3 = obj.contains(key)
 */
// @lc code=end

